/**
 * ...
 * @author Krzysztof Rozalski
 */

package hapi.physics.integration;
import hapi.physics.Acceleration;
import hapi.physics.AngularAcceleration;
import hapi.physics.Time;

class EulerIntegration implements NumericalIntegrationStrategy {

	var accelerator:Accelerator;
	
	public function new(accelerator) {
		this.accelerator = accelerator;
	}
	
	public function integrate(target:Integrateable, time:Time, delta:Time):Integrateable {
		var newTime = new Time(time.seconds + delta.seconds);
		var acc:Acceleration = accelerator.acceleration(target, newTime);
		var angularAcc:AngularAcceleration = accelerator.angularAcceleration(target, newTime);
		target.velocity.applyTo(target.position, delta);
		target.angularVelocity.applyTo(target.angle, delta);
		acc.applyTo(target.velocity, delta);
		angularAcc.applyTo(target.angularVelocity, delta);
		return target;
	}
}